﻿@{
    ViewBag.Title = "Cart";
    Layout = "~/Views/Shared/_Default.cshtml";
}
<div class="container-fluid" style="background-color: #fff;">
    <div class="page-header" style="border-top: 1px dotted #e2e2e2">
        <a id="snacks" name="snacks"></a>
        <h1 style="color: #892e65;">
            我的购物车 <small><i class="icon-double-angle-right"></i>方便快捷，美食自己送上门 </small>
        </h1>
    </div>
    <div class="widget-body" style="min-height: 620px;">
            <div class="tab-content padding-8 overflow-visible" style="margin:8px;">
                <div class="alert alert-info">
                    <strong>请注意：</strong> <br />
                    请仔细核对以上购物车中商品， 勾选您需要的商品后确认订单！<br />
                    
                </div>
            </div>
        <div class="widget-main padding-4">
            <div style="min-height:470px;" class="tab-content padding-8 overflow-visible">
                <div id="task-tab" class="tab-pane active">
                    <h4 class="smaller lighter green">
                        <i class="icon-list"></i>Shoping Cart
                    </h4>
                    <ul id="tasks" class="item-list ui-sortable">
                        @{
                            List<CollegeShop.Infrastructure.Entities.Entity.Goods> data = ViewBag.Commodities;
                            if (data != null && data.Any())
                            {
                                foreach (var item in data)
                                {
                            <li class="item-orange clearfix">
                                <div class="row-fluid line80">
                                    <div class="span5">
                                        <div style="display: inline;">
                                            <input class="commodityselected" type="checkbox" checked="checked" />
                                            <img alt="@item.GoodsTitel" style="width: 80px; height: 80px;" class="commodity-small" src="@item.Resource.Path" />
                                        </div>
                                        <div class="inline">
                                            <a href="javascript:;">@item.GoodsTitel 【@item.Style】</a>
                                        </div>
                                    </div>
                                    <div class="span2">
                                        <label class="inline">
                                            单价：￥@item.DefaultSalePrice.ToString("F2") 元
                                        </label>
                                    </div>
                                    <div class="span2">
                                        <label class="inline green bolder">
                                            现有库存
                                        </label>
                                    </div>
                                    <div class="span2">
                                        <span class="msg-body">
                                        <i style="cursor: pointer;" class="dominus icon-minus"></i>
                                        <span class="badge badge-important cartitem" item-id="@item.ID" item-price="@item.DefaultSalePrice.ToString("F2")">1</span>
                                        <i style="cursor: pointer;" class="doplus icon-plus"></i></span>
                                    </div>
                                    <div class="span1" style="text-align: center;">
                                        <a onclick="deleteitem(this)" href="javascript:;" item-id="@item.ID" class="red"><i class="icon-trash bigger-130"></i>&nbsp;删除 </a>
                                    </div>
                                </div>
                            </li>
                                }
                            }
                            else
                            {

                            }
                        }
                    </ul>
                </div>
                <div class="form-actions" style="margin-top: 0px; border: 1px solid #ccc;">
                    <div class="input-group pull-right">
                        合计：<i class="bolder red" id="carttotalprice" style="font-size: 18px;">@{decimal price = 0; data.ForEach(o => { price += o.DefaultSalePrice; });}@price.ToString("F2")</i> 元 
                        <a id="btnconfirmorder" onclick="goconfirm()" href="javascript:;" class="btn btn-primary">&nbsp;&nbsp;确定&nbsp;&nbsp;</a> 
                        <a href="/" class="btn btn-warning">&nbsp;继续购物&nbsp;</a>
                    </div>
                </div>
            </div>
            <br />
            <br />
        </div>
        <!-- /widget-main -->
    </div>
</div>
<form id="confirmfrom" action="/home/ConfirmOrder" method="post">
</form>
@section tail{
    <script type="text/javascript">
        if ($('.cartitem').length == 0) {
            delCookie('goodscart');
            window.location.href = "/";
            if ($.browser.msie && $.browser.version == 6) {
                window.event.returnValue = false;
            }
        }
        function goconfirm() {
            if ($('.commodityselected:checked').length == 0) {
                return;
            }
            var data = '';
            $('.cartitem').each(function () {
                var id = $(this).attr('item-id');
                var count = $(this).text();
                data += id + ':' + count + '$';
            });
            if (data.length > 0) {
                $('#confirmfrom').append($('<input type="hidden" name="items" value="'+data+'" />')).submit();
            }
        }
        function changecart() {
            var totalprice = 0;
            $('.cartitem').each(function () {
                var price = $(this).attr('item-price');
                var count = $(this).text();
                totalprice = parseFloat(totalprice) + parseFloat(price) * parseInt(count, 10);
                $('#carttotalprice').text(totalprice.toFixed(2));
            });
        }
        function deleteitem(sender) {
            if (confirm('确定要删除此商品吗？')) {
                $(sender).parent().parent().parent().remove();
                changecart();
                var id = $(sender).attr('item-id');
                var cookievalue = getCookie('goodscart');
                var arr = cookievalue.split(',');
                arr = removeItem(arr, id);
                setCookie('goodscart', arr.join());
            }
            if ($('.cartitem').length == 0) {
                window.location.href = "/";
                if ($.browser.msie && $.browser.version == 6) {
                    window.event.returnValue = false;
                }
            }
        }
        $('.dominus').click(function () {
            var obj = $(this).siblings('span');
            if (obj.text() == '1') {
                $(this).parent().parent().next('div:eq(0)').children('a').trigger('click');
                return;
            }
            obj.text(parseInt(obj.text(), 10) - 1);
            changecart();
        });
        $('.doplus').click(function () {
            var obj = $(this).siblings('span');
            obj.text(parseInt(obj.text(), 10) + 1);
            changecart();
        });
        $('.commodityselected').each(function () {
            $(this).click(function () {
                if ($('.commodityselected:checked').length == 0) {
                    $('#btnconfirmorder').addClass("disabled");
                } else {
                    $('#btnconfirmorder').removeClass("disabled");
                }
            });
        });
    </script>
}